package top.jolyoulu.codegenweb.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.jolyoulu.codegenweb.entity.bo.query.GenCodeTaskQueryBO;
import top.jolyoulu.codegenweb.entity.vo.GenCodeTaskVO;
import top.jolyoulu.codegenweb.service.bll.ApiGenCodeTaskService;
import top.jolyoulu.modules.mybatisplusmodule.plugin.page.JlPage;
import top.jolyoulu.webcommon.entity.ResultInfo;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 任务列表
 */
@RestController
@RequestMapping("/api/gen/code/task")
public class ApiGenCodeTaskController {

    @Autowired
    private ApiGenCodeTaskService apiGenCodeTaskService;

    /**
     * 任务列表
     */
    @GetMapping("/pageList")
    public ResultInfo<JlPage<GenCodeTaskVO>> pageList(GenCodeTaskQueryBO bo){
        JlPage<GenCodeTaskVO> res = apiGenCodeTaskService.pageList(bo);
        return ResultInfo.success(res);
    }

    /**
     * 下载压缩包
     */
    @GetMapping("/download/zip/{id}")
    public void downloadZip(@PathVariable("id") String id, HttpServletResponse response){
        apiGenCodeTaskService.downloadZip(id, response);
    }

    /**
     * 任务信息
     */
    @GetMapping("/get/{id}")
    public ResultInfo<GenCodeTaskVO> getById(@PathVariable String id) {
        GenCodeTaskVO res = apiGenCodeTaskService.getById(id);
        return ResultInfo.success(res);
    }

    /**
     * 删除任务
     */
    @DeleteMapping("/del")
    public ResultInfo del(@RequestBody List<String> ids){
        apiGenCodeTaskService.delByIds(ids);
        return ResultInfo.success();
    }
}